<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../node_modules/react/umd/react.development.js"></script>
    <script src="../node_modules/react-dom/umd/react-dom.development.js"></script>
    <script src="../node_modules/babel-standalone/babel.js"></script>
</head>
<body>
    <div id="app"></div>
    <script type="text/babel">
        class Parent extends React.Component {
            constructor(props) {
                super(props);

                this.state = {
                    b: true
                }
            }

            fn() {
                this.setState({
                    b: !this.state.b
                });
            }

            render() {
                return (
                    <div>
                        <input type="button" value="Be/Not to Be" onClick={this.fn.bind(this)} />
                        {this.state.b ? <Child />: ('')}
                    </div>
                );
            }
        }

        class Child extends React.Component {
            constructor(props) {
                super(props);
            }

            componentDidMount() {
                console.log('mount');
            }

            componentWillUnmount() {
                console.log('unmount');
            }


            render() { 
                console.log('child 渲染了');
                return (
                    <div>
                       <p>子组件在这里</p>
                    </div>
                );
            }
        }

        ReactDOM.render(
            <Parent />,
            document.getElementById('app')
        );
    </script>
</body>
</html>